/**
 * 
 */
package com.school.homeServlet.cmd;

import java.io.IOException;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;

import com.school.dao.UserManagerDao;
import com.school.dao.UserManagerDaoImpl;
import com.school.entity.NewRegistration;

/**
 * @author KK
 *
 */
public class NewStudentRegisterCommand implements HomeCommand {

	/* (non-Javadoc)
	 * @see com.school.homeServlet.cmd.HomeCommand#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.servlet.ServletConfig)
	 */
	public static Logger log = Logger.getLogger(NewStudentRegisterCommand.class.getSimpleName());
	@Override
	public void processRequest(HttpServletRequest req,
			HttpServletResponse resp, ServletConfig config)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		System.out.println("Entered process request------kkkkkkk");
			
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd");
		
		Date sqlDate = null;			///////////////
		java.util.Date utilDate = null;		///////
		try {
			utilDate = dateFormat.parse(req.getParameter("dob"));
			sqlDate = new java.sql.Date(utilDate.getTime());
		}
		catch (ParseException e) {
			e.printStackTrace();
		}						////////////////
		
		UserManagerDao obj1 = new UserManagerDaoImpl();
		NewRegistration newreg = new NewRegistration();
		
		newreg.setStudent_name(req.getParameter("sname"));
		newreg.setFather_name(req.getParameter("fname"));
		newreg.setDob(sqlDate);
		newreg.setAddress(req.getParameter("address"));
		newreg.setContact_no(req.getParameter("contact"));
		newreg.setCity(req.getParameter("city"));
		newreg.setEmail(req.getParameter("email"));
		newreg.setPrev_edu(req.getParameter("pre_edu"));
		newreg.setNew_class(req.getParameter("newclass"));
		
		String result = obj1.new_register(newreg);
		if(result != null)
		{
			req.setAttribute("ref", result);
			req.setAttribute("regSucc", true);
			req.setAttribute("newRegistrationForm", false);
			req.setAttribute("contactUs", false);
			req.setAttribute("examSchedule", false);
			req.setAttribute("examResult", false);
			req.setAttribute("interviewSchedule", false);
			req.setAttribute("interviewResult", false);
			
			
			RequestDispatcher dispatcher = req.getRequestDispatcher("/school_home.jsp");
			dispatcher.forward(req, resp);
		}
		
		
	//	obj1.new_register();

	}

}
